 <?php
/**
 * @CopyRight  (C)2006-2011 OE Development team Inc.
 * @WebSite    www.phpcoo.com，www.oecms.cn
 * @Author     XiangFeng <phpzac@foxmail.com>
 * @Brief      OEcms v3.x
 * @Update     2011.09.01
 * @Id         在线留言
**/
if(!defined('ALLOWGUEST')) {
	exit('Access Denied');
}
$action = Core_Fun::rec_post("action");
$mod = Core_Fun::rec_post("mod");

switch($action){
case "saveadd":{
	$bookuser    = Core_Fun::rec_post("bookuser",1);
	$title      = Core_Fun::rec_post("title",1);
	$gender      = Core_Fun::rec_post("gender",1);
	//$companyname = Core_Fun::rec_post("companyname",1);
	//$address     = Core_Fun::rec_post("address",1);
	//$trade       = Core_Fun::rec_post("trade",1);
	//$jobs        = Core_Fun::rec_post("jobs",1);
	$telephone   = Core_Fun::rec_post("telephone",1);
	$mobile      = Core_Fun::rec_post("mobile",1);
	$fax         = Core_Fun::rec_post("fax",1);
	$email       = Core_Fun::rec_post("email",1);
	$cateid      = Core_Fun::rec_post("cateid",1);
	$pageid      = Core_Fun::rec_post("pageid",1);
	if($cateid == 5){
	$content     = Core_Fun::rec_post("content",1);
	}else{
	$content     = Core_Fun::rec_post("content",1);
	$content    .= "我的地址为：".$address;
	}
	$founderr    = false;
	$isopen      = Core_Fun::rec_post("isopen",1);
	$isopen      = $isopen ? $isopen : 0;
	$flag        = 1-$isopen;
	
	if(!Core_Fun::ischar($bookuser)){
		$founderr = true;
		$errmsg  .= "姓名不能为空<br />";
	}
/* 	 if(!Core_Fun::ischar($title)){
	 	$founderr = true;
	 	$errmsg  .= "标题不能为空<br />";
 	} */
	//if(!Core_Fun::ischar($companyname)){
	//	$founderr = true;
	//	$errmsg  .= "公司名不能为空<br />";
//	}
	//if(!Core_Fun::ischar($address)){
		//$founderr = true;
		//$errmsg  .= "地址不能为空<br />";
	//}
//	if(!Core_Fun::ischar($trade)){
	//	$founderr = true;
	//	$errmsg  .= "行业不能为空<br />";
	//}
//	if(!Core_Fun::ischar($jobs)){
	//	$founderr = true;
	//	$errmsg  .= "职务不能为空<br />";
//	}
	if(!Core_Fun::ischar($telephone)){
		$founderr = true;
		$errmsg  .= "电话不能为空<br />";
	}
	if(!Core_Fun::ischar($content)){
		$founderr = true;
		$errmsg  .= "留言内容不能为空<br />";
	}
	if($founderr==true){
		Core_Fun::halt($errmsg,"",1);
	}

	$bookid = $db->fetch_newid("SELECT MAX(bookid) FROM ".DB_PREFIX."guestbook",1);
	session_start();
	$array  = array(
		'bookid'=>$bookid,
		'title'=>$title,
		'bookuser'=>$bookuser,
		'gender'=>$gender,
		'jobs'=>$jobs,
		'telephone'=>$telephone,
		'fax'=>$fax,
		'mobile'=>$mobile,
		'email'=>$email,
		'qqmsn'=>$qqmsn,
		'companyname'=>$companyname,
		'address'=>$address,
		'trade'=>$trade,
		'homepage'=>$homepage,
		'content'=>$content,
		'booktimeline'=>time(),
		'ip'=>Core_Fun::getip(),
		'flag'=>$flag, //set as not show default
		'username'=>$_SESSION['username'],
		'userid'=>$_SESSION['userid'],
		'isopen'=>$isopen,
		'cateid'=>$pageid,//修改过的文章id
	);

	$db->insert(DB_PREFIX."guestbook",$array);
	if($urlsuffix=='php'){
		$url = PATH_URL."guestbook.php";
	}else{
		if($config['routeurltype']==1){
			$url = PATH_URL."guestbook.html";
		}else{
			$url = PATH_URL."guestbook";
		}
	}
	
	$targeturl = Core_Fun::rec_post("targeturl"); 
	if($targeturl)
		$url = $targeturl;
	Core_Fun::halt($_SESSION['username']."留言成功，我们将会尽快给您联系，感谢您的支持！",$url,0);
	break;

}/* else{
	$page_title = $LANVAR['guestbook'];
	$tpl->assign("page_title",$page_title."-".$config['sitename']);
	$tpl->assign("page_metadescription",$config['metadescription']);
	$tpl->assign("page_metakeyword",$config['metakeyword']);
} */


case "saveadd_noname":{
	$bookuser    = Core_Fun::rec_post("bookuser",1);
	$title      = Core_Fun::rec_post("title",1);
	$gender      = Core_Fun::rec_post("gender",1);
	//$companyname = Core_Fun::rec_post("companyname",1);
	//$address     = Core_Fun::rec_post("address",1);
	//$trade       = Core_Fun::rec_post("trade",1);
	//$jobs        = Core_Fun::rec_post("jobs",1);
	$telephone   = Core_Fun::rec_post("telephone",1);
	$mobile      = Core_Fun::rec_post("mobile",1);
	$fax         = Core_Fun::rec_post("fax",1);
	$email       = Core_Fun::rec_post("email",1);
	$cateid      = Core_Fun::rec_post("cateid",1);
	$pageid      = Core_Fun::rec_post("pageid",1);
	if($cateid == 5){
	$content     = Core_Fun::rec_post("content",1);
	}else{
	$content     = Core_Fun::rec_post("content",1);
	$content    .= "我的地址为：".$address;
	}
	$founderr    = false;
	$isopen      = Core_Fun::rec_post("isopen",1);
	$isopen      = $isopen ? $isopen : 0;
	
	
	if(!Core_Fun::ischar($bookuser)){
		$founderr = true;
		$errmsg  .= "姓名不能为空<br />";
	}
	//if(!Core_Fun::ischar($title)){
	// 	$founderr = true;
	// 	$errmsg  .= "标题不能为空<br />";
 	//}
	//if(!Core_Fun::ischar($companyname)){
	//	$founderr = true;
	//	$errmsg  .= "公司名不能为空<br />";
//	}
	//if(!Core_Fun::ischar($address)){
		//$founderr = true;
		//$errmsg  .= "地址不能为空<br />";
	//}
//	if(!Core_Fun::ischar($trade)){
	//	$founderr = true;
	//	$errmsg  .= "行业不能为空<br />";
	//}
//	if(!Core_Fun::ischar($jobs)){
	//	$founderr = true;
	//	$errmsg  .= "职务不能为空<br />";
//	}

	if(!Core_Fun::ischar($content)){
		$founderr = true;
		$errmsg  .= "留言内容不能为空<br />";
	}
	if($founderr==true){
		Core_Fun::halt($errmsg,"",1);
	}

	$bookid = $db->fetch_newid("SELECT MAX(bookid) FROM ".DB_PREFIX."guestbook",1);
	session_start();
	$array  = array(
		'bookid'=>$bookid,
		'title'=>$title,
		'bookuser'=>$bookuser,
		'gender'=>$gender,
		'jobs'=>$jobs,
		'telephone'=>$telephone,
		'fax'=>$fax,
		'mobile'=>$mobile,
		'email'=>$email,
		'qqmsn'=>$qqmsn,
		'companyname'=>$companyname,
		'address'=>$address,
		'trade'=>$trade,
		'homepage'=>$homepage,
		'content'=>$content,
		'booktimeline'=>time(),
		'ip'=>Core_Fun::getip(),
		'flag'=>1, //set as not show default
		'username'=>$_SESSION['username'],
		'userid'=>$_SESSION['userid'],
		'isopen'=>$isopen,
		'cateid'=>$pageid,//修改过的文章id
	);

	$db->insert(DB_PREFIX."guestbook",$array);
	if($urlsuffix=='php'){
		$url = PATH_URL."guestbook.php";
	}else{
		if($config['routeurltype']==1){
			$url = PATH_URL."guestbook.html";
		}else{
			$url = PATH_URL."guestbook";
		}
	}
	
	$targeturl = Core_Fun::rec_post("targeturl"); 
	if($targeturl)
		$url = $targeturl;
	Core_Fun::halt($_SESSION['username']."留言成功，我们将会尽快给您联系，感谢您的支持！",$url,0);
	break;


/* {
	
	$page_title = $LANVAR['guestbook'];
	$tpl->assign("page_title",$page_title."-".$config['sitename']);
	$tpl->assign("page_metadescription",$config['metadescription']);
	$tpl->assign("page_metakeyword",$config['metakeyword']);
} */
}
default:
break;

}

if($mod="detail")
{
 $bookid = Core_Fun::rec_post("bookid");
  $array = $db->get_one("SELECT * FROM ".DB_PREFIX."guestbook WHERE `bookid`=\"".$bookid."\"");
  //var_dump($array);
  $tpl->assign("book",$array);
}
?>